from strategy.StrategyTemplate import StrategyTemplate
from utils.db import DbHandler
import pandas as pd
from strategy.big_data.big_data_common import concept_money_flow_now_column,concept_money_flow_his_column


class ConceptMoneyFlow(StrategyTemplate):
    """
    概念资金流入流出
    """
    def __init__(self):
        super(ConceptMoneyFlow, self).__init__()
        self.strategy_name = "概念资金流入流出"
        self.strategy_descrption = "概念资金流入流出"

    def run(self):
        db = DbHandler()
        db.create_session()
        pd_concepts_price = pd.read_sql_table('concept_money_flow', con=db.engine)

    def api(self, n, size=10):
        db = DbHandler()
        db.create_session()
        if n == 0:
            pd_concepts_price = pd.read_sql_table('concept_money_flow', con=db.engine)
            pd_concepts_price = pd_concepts_price[concept_money_flow_now_column]

        else:
            pd_concepts_price = pd.read_sql_table('concept_money_flow_' + str(n), con=db.engine)
            pd_concepts_price['涨幅'] = pd_concepts_price['涨幅'].str[:-2]

            pd_concepts_price = pd_concepts_price[concept_money_flow_his_column]

        pd_concepts_price.reset_index(inplace=True, drop=True)
        db.close_session()
        return pd_concepts_price

if __name__ == '__main__':
    ins = ConceptMoneyFlow()
    # ins.topN = 20
    ins.run()

